using System;
using System.Drawing;
using AForge;
using AForge.Imaging;

namespace MD.ImageProcessing.Cell
{
    public sealed class CellState
    {
        public CellState(int cellId)
        {
            CellId = cellId;
        }

        public CellState(Blob blob)
        {
            State = blob;
        }

        public int CellId { get; set; }

        //public Guid CellId { get; set; }

        public Blob State { get; set; }

        public IntPoint Point
        {
            get { return State.CenterOfGravity; }
        }

        public Rectangle BoundRect { get; set; }

        public static bool Compare(CellState mainCellState, CellState candidateCellState, double countEps = 0.3)
        {
            var intersection = Rectangle.Intersect(mainCellState.BoundRect, candidateCellState.BoundRect).IsEmpty;
            if (!intersection)
            {
                return false;
            }
            var pointEpsCount = (double)Math.Abs(mainCellState.State.Area - candidateCellState.State.Area) / mainCellState.State.Area;
            var c = mainCellState.State.Fullness - candidateCellState.State.Fullness < 0.1;
            var d = mainCellState.State.CenterOfGravity.DistanceTo(candidateCellState.State.CenterOfGravity) < 10;
            //count equal values
            return intersection && (pointEpsCount < countEps) && c && d;
        }
    }
}